//Date: 2024-12-26 09:53:01
#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int rd() {
    int s=0,m=0;char ch=getchar();
    while(!isdigit(ch)) {if(ch=='-')m=1;ch=getchar();}
    while( isdigit(ch)) s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
    return m?-s:s;
}
bool MBE;
namespace SOLVER {
int n,C,b[500005],m,ret,now=1e8,cnt;vector<int> a[500005];map<int,int> mp;
void add(int x) {ret-=b[mp[x]],ret+=b[++mp[x]],cnt++;}
struct Node {int t,x,y;} d[1000005];bool cmp(Node d1,Node d2) {return d1.t>d2.t;}
vector<int> ans;int Mn=1e18;
void chk() {if(ret<Mn) Mn=ret,ans.clear(),ans.emplace_back(now);else if(ret==Mn) ans.emplace_back(now);}
//时间<=t那么x会在a[x][y]加入
void MAIN() {
    cin>>n;for(int i=1;i<=n;i++) for(int l=rd();l;l--) a[i].emplace_back(rd());
    cin>>C;for(int i=1;i<=n;i++) b[i]=rd()*i;
    for(int i=1;i<=n;i++) if(a[i].size()) {
        ret+=now*C+(a[i][a[i].size()-1]-a[i][0])*C,add(a[i][0]);
        for(int j=1;j<a[i].size();j++) d[++m]={a[i][j]-a[i][j-1],i,j};
    }
    sort(d+1,d+m+1,cmp);chk();
    // for(int i=1;i<=m;i++) cerr<<d[i].t<<' '<<d[i].x<<' '<<a[d[i].x][d[i].y]<<endl;
    for(int i=1;i<=m;i++) {
        int j=i;while(j<m&&d[j+1].t==d[i].t) j++;
        //now->d[i].t+1
        ret-=(now-(d[i].t+1))*cnt*C,now=d[i].t+1,chk();
        //now->d[i].t
        ret-=cnt*C,now=d[i].t;for(int k=i;k<=j;k++) add(a[d[k].x][d[k].y]);chk();
        i=j;
    }
    ret-=(now-1)*cnt*C,now=1,chk();
    sort(ans.begin(),ans.end());ans.erase(unique(ans.begin(),ans.end()),ans.end());
    cout<<Mn<<' '<<ans.size()<<endl;
    for(int x:ans) printf("%lld ",x);
}
}
bool MED;
signed main() {
    freopen("list.in","r",stdin);freopen("list.out","w",stdout);
    for(int tt=1;tt;tt--) SOLVER::MAIN();
    cerr<<(&MBE-&MED)/1024<<" KB, "<<1000*clock()/CLOCKS_PER_SEC<<" ms\n";
    return 0;
}